<template>
	<view class="">
		<view class="u-p-20">
			<view class="bg_FFFFFF u-flex">
				<view @click="tabClick(1)" class="u-w-355 u-h-100 u-text-center bg_F4F4F4FF u-l-h-100"
					:class="give==1?'bg_FFFFFF':''">快递商品</view>
				<view @click="tabClick(2)" class="u-w-356 u-h-100 u-text-center bg_F4F4F4FF u-l-h-100"
					:class="give==2?'bg_FFFFFF':''">到店自提</view>
			</view>
			<!-- 配送信息 -->
			<view class="u-m-t-20 u-flex u-row-between bg_FFFFFF u-p-20 u-b-r-16" @click="address_show=true">
				<view class="u-flex">
					<u-icon name="map" color='#FB473CFF' size='30'></u-icon>
					<view class="u-p-l-10" v-if="!selectAdd.name">暂无收货地址</view>
					<view v-else class=" u-p-l-10">
						<view class="">
							<text class="u_inline-block u-p-r-30 u-weight">{{selectAdd.name}}</text>
							<text class="u_inline-block u-weight">{{selectAdd.phone}}</text>
						</view>
						<view class="u-p-t-10 u-font-24">{{selectAdd.modify_region.name}}</view>
					</view>
				</view>
				<u-icon name="arrow-right" size='20'></u-icon>
			</view>
			<view class="bg_FFFFFF u-p-30 u-m-t-30 u-b-r-16" v-for="(item,index) in userinfo.items" :key="item.id">
				<view class="u-flex" style="border-bottom: 1rpx solid #F1F1F1FF;">
					<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/shop.png" mode="aspectFill" width="36rpx"
						height='36rpx'>
					</u-image>
					<view class="u-weight u-p-b-10 u-m-l-20">{{item.shop_name}}</view>
				</view>

				<view class="" v-for="(items,index1) in item.goods" :key="index1">
					<view class="u-p-30 u-flex" style="border-bottom: 1rpx solid #F1F1F1FF;">
						<view class="  u-w-178 u-h-178">
							<u-image :src="items.thumb_url" mode="aspectFill" width="178rpx" height='178rpx'></u-image>
						</view>
						<view class="  u-w-600 u-p-l-20">
							<view class=" u-weight">{{items.goods_name}}</view>
							<view class="u-font-20 u-m-t-20 cl_999 "
								style="background-color:#F8F8F8;display: inline-block; padding: 0 10rpx;">
								{{items.spece_value_title}}
							</view>
							<view class="u-flex u-row-between u-m-t-30">
								<view class="">
									<view class="u-flex" style="color:#FC3533FF ;">
										<text>￥{{items.price}}</text>
									</view>
								</view>
								<view class="u-p-l-40">×{{items.num}}</view>
							</view>
						</view>

					</view>
				</view>
				<view class="u-m-t-20 u-flex brb_F4F4F4">
					<u-input v-model="note" placeholder="请输入备注信息"></u-input>
				</view>
				<view v-if="type==2" class="u-m-t-20 u-flex u-row-between">
					<view class="u-font-24 cl_454545FF">优惠券</view>
					<view class="cl_FF5502FF u-font-20" @click="choes_card(item)">{{item.coupon_des}}
						<u-icon name='arrow-right' color='#000000'></u-icon>
					</view>
				</view>
				<view v-if="give==1" class="u-p-20 u-flex u-row-between u-font-24">
					<view class="" style="color: #454545FF;">快递运费</view>
					<view class="u-weight">{{item.delivery_amount}}</view>
				</view>
			</view>
			<!-- 价格明细 -->
			<view class="u-w-710 bg_FFFFFF u-p-20 u-m-t-30 u-b-r-16">
				<view v-if="type==2" class="u-w-670 u-m-b-20 u-flex">
					<u-radio-group class="u-w-670 u-flex u-row-center" v-model="normal_chose" @change="radioGroupChange">
						<u-radio active-color="#FC3533FF" v-for="(item, index) in normal_chose_list" :key="index"
							:name="item.normal_chose">
							{{item.des}}
						</u-radio>
					</u-radio-group>
				</view>
				<view v-if="type==3 || type==2" class="u-flex u-row-between">
					<view class="u-weight cl_454545FF">抵扣金</view>
					<view class="deduct cl_FB473CFF u-flex">
						<view class="u-m-r-10">
							￥{{userinfo.deduct}}
						</view>
						<u-checkbox v-model="deductShow" @change="deductChange" active-color="#FB473C" shape="circle">
						</u-checkbox>
					</view>
				</view>
				<view class="u-m-t-40 u-font-30 u-weight">价格明细</view>
				<view v-if="type==3" class="u-m-t-20 u-flex u-row-between">
					<view class="u-font-24 cl_454545FF">抵扣金金额</view>
					<view class="u-weight u-font-28">￥{{userinfo.deduct_amount}}</view>
				</view>
				<view class="u-m-t-20 u-flex u-row-between">
					<view class="u-font-24 cl_454545FF">商品价格</view>
					<view class="u-weight u-font-28">￥{{userinfo.goods_amount}}</view>
				</view>
				<view class="u-m-t-20 u-flex u-row-between">
					<view class="u-font-24 cl_454545FF">积分抵扣</view>
					<view class="u-weight u-font-28">{{userinfo.score_amount}}</view>
				</view>
				<view class="u-m-t-20 u-flex u-row-between" v-if="pay_class=='cart'">
					<view class="u-font-24 cl_454545FF">积分折扣</view>
					<view class="u-flex">
						<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/money.png" mode="aspectFill" width="30rpx"
							height='30rpx'>
						</u-image>
						<view class="cl_FF5502FF u-font-20">{{userinfo.score_amount}}</view>
					</view>
				</view>


				<view class="u-m-t-20 u-flex u-row-between">
					<view class="u-font-24 cl_454545FF">合计</view>
					<view class="u-weight cl_FF5502FF">￥{{userinfo.pay_amount}}</view>
				</view>
			</view>
			<!-- 支付方式 -->
			<view v-if="userinfo.pay_amount>0" class="u-p-30">
				<view class="u-flex-col u-col-center u-font-28">- 支付方式 -</view>
				<!-- <view class="bg_FFFFFF u-font-20 u-w-300 u-m-t-10 u-auto" style="color:#FB473C;padding: 0 10rpx;">支付剩余时间：01:58:26</view> -->
			</view>
			<!-- 支付类型 -->
			<view v-if="userinfo.pay_amount>0" class="bg_FFFFFF u-b-r-12">
				<view @click="pays='deposit'" class="u-flex u-row-between u-p-30" style="border-bottom: 1rpx solid #F6F6F6FF;">
					<view class="u-flex">
						<view class=" u-flex">
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/card.png" mode="aspectFill" width="50rpx"
								height='50rpx'>
							</u-image>
							<view class="u-m-l-30 u-font-28 ">钱包支付</view>
						</view>
						<view class="u-m-l-30 cl_898989FF u-font-24">可用<text class="cl_FB473CFF">￥{{yu.user_wallet || 0}}</text>
						</view>
					</view>

					<view class="u-flex">
						<!-- <view class="u-m-r-20 cl_FB473CFF">-￥{{userinfo.goods_amount}}</view> -->
						<view class="">
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/c1.png" mode="aspectFill" width="30rpx"
								height='30rpx' v-if="pays=='deposit'"></u-image>
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/c.png" mode="aspectFill" width="30rpx"
								height='30rpx' v-else>
							</u-image>
						</view>
					</view>

				</view>
				<!-- <view style="color: #afacac;font-size: 26rpx;padding: 14rpx;">请充值余额并优先选择余额支付</view> -->

				<view @click="openEpayDialog" class="u-flex u-row-between u-p-30" style="border-bottom: 1rpx solid #F6F6F6FF;">
					<view class="">
						<view class=" u-flex">
							<u-image src="http://xcx.itcwc.com/wxImg/5dcf4786109a5.png" mode="aspectFill" width="50rpx"
								height='50rpx'>
							</u-image>
							<view class="u-m-l-30 u-font-28 ">易支付</view>
						</view>

					</view>
					<view class="u-flex">
						<!-- <view class="u-m-r-20 cl_FB473CFF">-￥{{userinfo.goods_amount}}</view> -->
						<view class="">
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/c1.png" mode="aspectFill" width="30rpx"
								height='30rpx' v-if="pays == 'epay'"></u-image>
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/c.png" mode="aspectFill" width="30rpx"
								height='30rpx' v-else>
							</u-image>
						</view>
					</view>
				</view>

				<!-- #ifdef MP-WEIXIN || H5 -->
				<view @click="pays='wechat'" v-if="is_wechat_switch == 1" class="u-flex u-row-between u-p-30"
					style="border-bottom: 1rpx solid #F6F6F6FF;">
					<view class="">
						<view class=" u-flex">
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/wx.png" mode="aspectFill" width="50rpx"
								height='50rpx'>
							</u-image>
							<view class="u-m-l-30 u-font-28 ">微信支付</view>
						</view>

					</view>
					<view class="u-flex">
						<!-- <view class="u-m-r-20 cl_FB473CFF">-￥{{userinfo.goods_amount}}</view> -->
						<view class="">
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/c1.png" mode="aspectFill" width="30rpx"
								height='30rpx' v-if="pays=='wechat'"></u-image>
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/c.png" mode="aspectFill" width="30rpx"
								height='30rpx' v-else>
							</u-image>
						</view>
					</view>
				</view>
				<!-- #endif -->

				<!-- #ifdef MP-ALIPAY || H5 || APP -->
				<view @click="pays='alipay'" v-if="is_alipay_switch == 1" class="u-flex u-row-between u-p-30"
					style="border-bottom: 1rpx solid #F6F6F6FF;">
					<view class="">
						<view class=" u-flex">
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/zf.png" mode="aspectFill" width="50rpx"
								height='50rpx'>
							</u-image>
							<view class="u-m-l-30 u-font-28 ">支付宝支付</view>
						</view>
					</view>
					<view class="u-flex">
						<view class="">
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/c1.png" mode="aspectFill" width="30rpx"
								height='30rpx' v-if="pays=='alipay'"></u-image>
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/c.png" mode="aspectFill" width="30rpx"
								height='30rpx' v-else>
							</u-image>
						</view>
					</view>
				</view>
				<!-- #endif -->

			</view>
		</view>
		<view class="u-h-150">

		</view>
		<!-- 立即支付 -->
		<view class="u-fix u-h-120 u-b-0 u-w-750 u-p-20 bg_FFFFFF">
			<!-- <view class=" u-w-640 u-h-98 u-text-center">提交</view> -->
			<view @click="payTips" class="u-h-98 bl2C_3F u-l-h-98 u-text-center u-b-r-20 u-auto"
				style="letter-spacing: 4rpx;color: #ffffff;">立即支付</view>
		</view>

		<!-- 易支付选择弹窗 -->
		<u-popup v-model="showEpayDialog" mode="center" width="80%" border-radius="10">
			<view class="epay-dialog">
				<view class="epay-dialog-title">请选择支付方式</view>
				<view class="epay-dialog-content">
					<view class="epay-payment-option" @click="selectEpayMethod('wxpay')">
						<view class="radio-button">
							<view class="radio-inner" :class="{ 'radio-selected': params.epay_type === 'wxpay' }"></view>
						</view>
						<view class="payment-icon">
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/wx.png" mode="aspectFill" width="40rpx"
								height='40rpx'></u-image>
						</view>
						<view class="payment-name">微信支付</view>
					</view>
					<view class="epay-payment-option" @click="selectEpayMethod('alipay')" v-if="!isWechatMP">
						<view class="radio-button">
							<view class="radio-inner" :class="{ 'radio-selected': params.epay_type === 'alipay' }"></view>
						</view>
						<view class="payment-icon">
							<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/zf.png" mode="aspectFill" width="40rpx"
								height='40rpx'></u-image>
						</view>
						<view class="payment-name">支付宝支付</view>
					</view>
				</view>
				<view class="epay-dialog-footer">
					<view class="epay-dialog-btn cancel-btn" @click="showEpayDialog = false">取消</view>
					<view class="epay-dialog-btn confirm-btn" @click="confirmEpayMethod">确定</view>
				</view>
			</view>
		</u-popup>

		<!-- 选择规格大小 -->
		<u-select v-model="show" :list="list1" @cancel='show=false' @confirm='confirm'></u-select>

		<!-- 选择优惠券 -->
		<u-popup v-model="show" mode='bottom'>
			<view class="u-p-20 cl_333">
				<view class="u-flex u-row-between">
					<view class="u-font-30 u-weight u-m-l-30">店铺优惠券</view>
					<u-image @click='show=false' src="https://www.sqkjkj.vip/wxImg/common/collectCoupons/close.png"
						mode="aspectFill" width="44rpx" height='44rpx'>
					</u-image>
				</view>
				<scroll-view :scroll-y='true'>
					<view class="" style="height: 600rpx;">
						<view v-for="(item,index) in card_list" :key="index" @click="selectCoupon(item)" class="u-p-10 u-m-t-20">
							<view class="bg_FFFFFF bs_CCCCCC u-w-660 u-b-r-10 u-t-10 u-p-l-20 u-p-r-20 u-p-t-40 u-p-b-40">
								<view class="u-weight">
									{{item.type==1?'无门槛':item.type==2?'满减券':item.type==3?'折扣券':'消费券'}}
								</view>
								<view class="u-flex u-row-between">
									<view class="">
										<view class="cl_1C1C1CFF u-font-28 u-weight u-p-6">{{item.title}}</view>
									</view>
									<view v-if="item.type==1 || item.type==4" class="">
										<text class="cl_FC3533FF u-font-26">￥</text>
										<text class="cl_FC3533FF ">{{item.use_money}}</text>
										<u-icon name="arrow-right" size="35"></u-icon>
									</view>
									<view v-if="item.type==3" class="">
										<text class="cl_FC3533FF ">{{item.discount}}</text>
										<text class="cl_FC3533FF u-font-26">折</text>
										<u-icon name="arrow-right" size="35"></u-icon>
									</view>
									<view v-if="item.type==2" class="">
										<text class="cl_FC3533FF ">满{{item.limit_money}}-{{item.use_money}}</text>
										<u-icon name="arrow-right" size="30"></u-icon>
									</view>
								</view>
							</view>
						</view>

					</view>
				</scroll-view>

			</view>

		</u-popup>

		<u-mask :show="shows" mode='center'>
			<view class="warp">
				<view class="u-w-700 u-auto bg_FFFFFF u-p-20 u-b-r-20">
					<view class="u-p-20 u-text-right" @click.stop="shows=false">
						<u-icon name="close-circle-fill" color="#999999" size="55"></u-icon>
					</view>
					<u-message-input v-if="shows" :focus="true" :maxlength='6' @change="change" @finish="finish">
					</u-message-input>
				</view>
			</view>
		</u-mask>

		<u-popup v-model="address_show" mode='bottom' :closeable='true'>
			<view class="u-p-20">
				<view class="u-text-center u-p-t-30">选择收货地址</view>

				<view class="u-flex-col u-col-center u-m-t-50" v-if="address.length==0">
					<u-image src="https://www.sqkjkj.vip/wxImg/1.png" width='100rpx' height='100rpx'></u-image>
					<view class="cl_999 u-font-30 u-m-t-30">暂无收货地址</view>
				</view>

				<scroll-view scroll-y="true">
					<view class="u-h-300">
						<view class="u-p-t-20 u-flex" v-for="(item,index) in address" :key="index">
							<view class="">
								<u-image src="https://www.sqkjkj.vip/wxImg/car/img2.png" mode="aspectFill" width="40rpx" height='40rpx'
									v-if="addres_id==item.id">
								</u-image>
								<u-image src="https://www.sqkjkj.vip/wxImg/car/img.png" mode="aspectFill" width="40rpx" height='40rpx'
									v-else @click='choes(item)'>
								</u-image>


							</view>
							<view class="u-p-l-40">
								<view class="u-flex">
									<view class="u-font-24">{{item.name}}</view>
									<view class=" u-font-24 u-p-l-20">{{item.phone}}</view>
								</view>
								<view class="u-p-10 u-font-20 cl_999">{{item.modify_region.name}}</view>
							</view>
						</view>
					</view>
				</scroll-view>
				<view class="bg_FFFFFF">
					<u-row>
						<u-col span='6'>

							<view class="u-w-310 u-m-t-50 u-b-r-14 u-h-90 u-l-h-90 u-font-30 bg_FF5502FF u-text-center cl_FFF"
								@click="$u.route('/pages/address/addAddress')">添加新地址</view>

						</u-col>
						<u-col span='6'>
							<view class="u-w-310 u-m-t-50 u-b-r-14 u-h-90 u-l-h-90 u-font-30 bg_FF5502FF u-text-center cl_FFF"
								@click="address_show=false">确定</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-popup>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 优惠券弹窗
			show: true,
			// 选择优惠券
			choese: 1,
			// 配送方式
			give: 1,
			// 商品信息
			list: {},
			// 选择规格弹窗
			show: false,
			// 规格大小
			sizes: 'M',
			// 交易密码
			value: '',
			// 支付方式
			pays: 'deposit',
			// 是否使用积分
			pays1: 'jf',
			// 规格数据
			list1: [{
				value: '1',
				label: 'M'
			},
			{
				value: '2',
				label: 'S'
			}
			],
			transport_type: 1,
			userinfo: '',
			yu: '',
			arr: [],
			// 密码输入
			shows: false,
			massage_pay: '',
			// 选择地址
			address_show: false,
			// 地址列表
			address: [],
			addres_id: '',
			selectAdd: '',
			type: '',
			pay_class: '',
			card_list: [],
			shop_id: '',
			use_coupon: [],
			deductShow: false,
			note: '',
			isPayType: '',
			normal_chose_list: [],
			normal_chose: 'b',
			showWechatPay: true,
			params: {
				epay_type: 'wxpay',
				method: '',
			},
			showEpayDialog: false,
			isWechatMP: false,
			is_wechat_switch: '1',
			is_alipay_switch: '1',
		}
	},

	onLoad(obj) {
		this.type = obj.order_type
		this.pay_class = obj.buy_source
		this.wechatPaySwitch()
		this.detectDeviceType()
		console.log(this.pay_class, 'this.pay_class')

		let userinfoObj = uni.getStorageSync("userinfo")

		// #ifdef MP-WEIXIN
		this.is_wechat_switch = userinfoObj.mini_wechat_switch
		// #endif
		// #ifdef H5
		this.is_wechat_switch = userinfoObj.h5_wechat_switch
		// #endif
		// #ifdef APP-PLUS
		this.is_wechat_switch = userinfoObj.app_wechat_switch
		// #endif
		this.is_alipay_switch = userinfoObj.alipay_switch
	},
	onShow() {
		this.shows = false
		this.yu = uni.getStorageSync("userinfo")
		this.userinfo = uni.getStorageSync("pay_massage")
		this.normal_chose_list = this.userinfo.normal_chose_list
		if (this.userinfo.items[0].addressee_name) {
			this.selectAdd = {
				id: this.userinfo.items[0].address_id,
				name: this.userinfo.items[0].addressee_name,
				phone: this.userinfo.items[0].addressee_telphone,
				modify_region: {
					name: this.userinfo.items[0].address
				}
			}
		}
		// console.log(this.userinfo);
		this.massage()
		// 获取我的余额
		this.yu = uni.getStorageSync("userinfo")
		this.choes_address()
		this.use_coupon = []
	},
	methods: {
		// 检测设备类型并设置相应的method参数
		detectDeviceType() {
			// #ifdef H5
			this.params.method = 'web' // H5环境使用web
			this.isWechatMP = false
			// #endif

			// #ifdef MP-WEIXIN
			this.params.method = 'jsapi' // 微信小程序环境使用jsapi
			this.isWechatMP = true
			// #endif

			// #ifdef MP-ALIPAY
			this.params.method = 'jsapi' // 支付宝小程序环境使用jsapi
			this.isWechatMP = false
			// #endif

			// #ifdef APP-PLUS
			this.params.method = 'web' // APP环境使用app
			this.isWechatMP = false
			// #endif

			console.log('当前设备类型:', this.params.method)
		},
		wechatPaySwitch() {
			this.$api.wechatPaySwitch({}, (res) => {

				// #ifdef MP-WEIXIN
				if (res.data.data.mini != 1) {
					this.pays = 'deposit'
					this.showWechatPay = false
				}
				//  #endif
				// #ifdef APP-PLUS
				if (res.data.data.mini != 1) {
					this.pays = 'alipay'
					this.showWechatPay = false
				}
				// #endif
				// #ifdef H5
				if (res.data.data.mini != 1) {
					this.pays = 'deposit'
				}
				// #endif
			})
		},
		tabClick(type) {
			this.give = type
			let params = {
				buy_source: this.pay_class,
				order_type: this.type,
				use_coupon: this.use_coupon,
				sku_details: this.arr,
				transport_type: this.give,
				address_id: this.selectAdd.id,
				use_deduct: this.type == 3 && this.deductShow ? 1 : 0
			}
			this.addres_id = ''

			this.confirm_order_page(params)
		},
		deductChange(e) {
			this.deductShow = e.value
			let params = {
				buy_source: this.pay_class,
				order_type: this.type,
				use_coupon: this.use_coupon,
				sku_details: this.arr,
				transport_type: this.give,
				address_id: this.selectAdd.id,
				use_deduct: (this.type == 3 || this.type == 2) && this.deductShow ? 1 : 0,
				normal_chose: this.normal_chose
			}
			this.confirm_order_page(params)
		},
		// 选择地址
		choes_address() {
			this.$api.my_address_list({}, res => {
				if (res.data.code == 1) {
					this.address = res.data.data.data
					for (var i = 0; i < this.address.length; i++) {
						this.address[i].modify_region.name = (this.address[i].modify_region.name).split('/')
						this.address[i].modify_region.name = this.address[i].modify_region.name[0] + '-' + this
							.address[i].modify_region.name[1] + '-' + this.address[i].modify_region.name[2] +
							'-' +
							this.address[i].addr
					}
				}
			})
		},
		massage() {
			this.arr = []
			if (this.userinfo.items) {
				for (var i = 0; i < this.userinfo.items[0].goods.length; i++) {
					let massage = {
						goods_item_id: this.userinfo.items[0].goods[i].shop_goods_item_id,
						num: this.userinfo.items[0].goods[i].num
					}
					this.arr.push(massage)
				}
			}
		},
		choes(item) {
			this.addres_id = item.id
			this.selectAdd = item
			console.log(this.selectAdd)
		},
		// 点击确定选择规格
		confirm(e) { },
		// 点击选择可用优惠券
		choes_card(obj) {
			this.card_list = obj.coupon_useable_list
			this.shop_id = obj.shop_id
			if (this.card_list.length == 0) {
				uni.showToast({
					icon: 'none',
					title: '暂无可用优惠券'
				})
			} else {
				this.show = true
			}
		},
		radioGroupChange(e) {
			let params = {
				buy_source: this.pay_class,
				order_type: this.type,
				use_coupon: this.use_coupon,
				sku_details: this.arr,
				transport_type: this.give,
				address_id: this.selectAdd.id,
				use_deduct: (this.type == 3 || this.type == 2) && this.deductShow ? 1 : 0,
				normal_chose: this.normal_chose
			}
			this.confirm_order_page(params)
		},
		selectCoupon(item) {
			if (this.use_coupon.length == 0) {
				this.use_coupon.push({
					shop_id: this.shop_id,
					member_coupon_id: item.id
				})
			} else {
				this.use_coupon.forEach((res, index) => {
					if (this.shop_id == res.shop_id) {
						this.use_coupon.splice(index, 1)
						this.use_coupon.push({
							shop_id: this.shop_id,
							member_coupon_id: item.id
						})
					} else {
						this.use_coupon.push({
							shop_id: this.shop_id,
							member_coupon_id: item.id
						})
					}
				})
			}
			let params = {
				buy_source: this.pay_class,
				order_type: this.type,
				use_coupon: this.use_coupon,
				sku_details: this.arr,
				transport_type: this.give,
				address_id: this.selectAdd.id,
				use_deduct: (this.type == 3 || this.type == 2) && this.deductShow ? 1 : 0,
				normal_chose: this.normal_chose
			}
			this.confirm_order_page(params)
		},
		confirm_order_page(params) {
			this.$api.confirm_order_page(params, res => {
				if (res.data.code == 1) {
					this.userinfo = res.data.data
					this.show = false
				}
			})
		},
		payTips() {
			if (this.give == 1) {
				this.transport_type = 1
			} else {
				this.transport_type = 2
			}
			if (this.address.length == 0 || this.selectAdd.id == null) {
				uni.showToast({
					icon: 'error',
					title: "请先添加地址"
				})
				this.address_show = true
			} else {
				uni.showModal({
					title: '提示',
					content: `是否确认配送方式为：${this.give == 1 ? '快递商品' : '到店自提'}`,
					success: (s) => {
						if (s.confirm) {
							this.true_pays()
						}
					}
				})
			}
		},
		// 点击立即支付
		true_pays() {
			this.payMent()
			// if (this.pays == 'deposit') {
			// 易支付
			// if (uni.getStorageSync('userinfo').have_trade_pwd == 0) {
			// 	uni.showModal({
			// 		title: '提示',
			// 		content: '请先设置余额支付密码',
			// 		success: (res) => {
			// 			if (res.confirm) {
			// 				this.$u.route('/pages/changePayPassword/changePayPassword')
			// 			}
			// 		}
			// 	})
			// 	return
			// }
			// this.shows = true
			// 	this.payMent()
			// } else if (this.pays == 'epay') {
			// 	this.payMent()
			// } else {
			// 	this.payMent()
			// }
		},
		change(e) {
			console.log('内容改变，当前值为：' + e);
		},
		finish(e) {
			console.log('输入结束，当前值为：' + e);
			if (this.isPayType) {
				this.pay(e)
			} else {
				this.payMent(e)
			}
		},
		payMent(password = '') {
			// 余额支付下单
			if (this.pays == 'deposit' || this.pays == 'wechat' || this.pays == 'alipay' || this.pays == 'epay') {
				if (this.pay_class == 'buy_now') {
					let oneParams = {
						address_id: this.selectAdd.id,
						buy_source: this.pay_class,
						order_type: this.type,
						sku_details: this.arr,
						transport_type: this.transport_type,
						regcode: uni.getStorageSync('regcode'),
						note: this.note,
						use_coupon: this.use_coupon,
						use_deduct: (this.type == 3 || this.type == 2) && this.deductShow ? 1 : 0,
						normal_chose: this.normal_chose
					}
					this.$api.true_pays_list(oneParams, res => {
						if (res.data.code == 1) {
							this.addres_id = ''
							this.massage_pay = res.data.data
							if (this.pays == 'deposit') {
								// if (uni.getStorageSync('userinfo').have_trade_pwd == 0) {
								// 	uni.showModal({
								// 		title: '提示',
								// 		content: '请先设置余额支付密码',
								// 		success: (res) => {
								// 			if (res.confirm) {
								// 				this.$u.route(
								// 					'/pages/changePayPassword/changePayPassword'
								// 				)
								// 			} else {

								// 			}
								// 		}
								// 	})
								// 	return
								// }
								// this.shows = true
								// console.log(res.data.data)
								this.massage_pay = res.data.data
								this.pay()
							} else if (this.pays == 'epay') {
								// 易支付
								let params = {
									target_id: this.massage_pay.trade_id,
									target_type: this.massage_pay.target_type,
									pay_type: this.pays,
									total_amount: this.massage_pay.total_amount,
									type: this.params.epay_type,
									method: this.params.method,
									trade_pwd: password,
									// 根据不同平台设置不同的client参数
									// #ifdef APP-PLUS
									client: 'APP',
									// #endif
									// #ifdef MP-WEIXIN || MP-ALIPAY
									client: 'JSAPI',
									// #endif
									// #ifdef H5
									client: 'WAP',
									// #endif
								}
								this.$com.easyPay(params, this.pays);
							} else if (this.pays == 'wechat' || this.pays == 'alipay') {
								let params = {
									target_id: this.massage_pay.trade_id,
									target_type: this.massage_pay.target_type,
									pay_type: this.pays,
									total_amount: this.massage_pay.total_amount,
									// #ifdef APP-PLUS
									client: 'APP',
									// #endif
									// #ifdef MP-WEIXIN || MP-ALIPAY
									client: 'JSAPI',
									// #endif
									// #ifdef H5
									client: 'WAP',
									// #endif
								}
								// #ifdef APP-PLUS
								this.$com.wxPay(params, this.pays).then(ok => {
									this.$refs.uToast.show({
										title: ok.data.msg,
										type: 'success',
										callback: cal => {
											// this.$u.route({
											// 	type: 'reLaunch',
											// 	url: '/pages/my/my'
											// })
											this.paySucess()

										}
									})
								}).catch((err) => {
									this.isPayType = true
									console.log('出错了！！！！catch', this.isPayType)
								})
								// #endif
								// #ifdef MP-WEIXIN

								this.$com.weChatPay(params, this.pays).then(ok => {
									this.$refs.uToast.show({
										title: ok.data.msg,
										type: 'success',
										callback: cal => {
											// this.$u.route({
											// 	type: 'reLaunch',
											// 	url: '/pages/my/my'
											// })
											this.paySucess()

										}
									})
								}).catch((err) => {
									this.isPayType = true
								})
								// #endif

								// #ifdef MP-ALIPAY

								this.$com.aliPay(params, this.pays).then(ok => {
									this.$refs.uToast.show({
										title: ok.data.msg,
										type: 'success',
										callback: cal => {
											// this.$u.route({
											// 	type: 'reLaunch',
											// 	url: '/pages/my/my'
											// })
											this.paySucess()

										}
									})
								}).catch((err) => {
									this.isPayType = true
								})

								// #endif

							}
						} else {
							uni.showToast({
								icon: 'error',
								title: res.data.msg
							})
						}
					})
				} else if (this.pay_class == 'cart') {
					this.$api.true_pays_list({
						address_id: this.userinfo.items[0].address_id,
						buy_source: this.pay_class,
						order_type: this.type,
						transport_type: this.transport_type,
						use_coupon: this.use_coupon,
						regcode: uni.getStorageSync('regcode'),
						note: this.note,
						use_coupon: this.use_coupon,
						use_deduct: (this.type == 3 || this.type == 2) && this.deductShow ? 1 : 0,
					}, res => {
						if (res.data.code == 1) {

							// 显示加载中
							uni.showLoading({
								title: '支付处理中...',
								mask: true
							});

							this.massage_pay = res.data.data
							if (this.pays == 'deposit') {
								// this.shows = true
								this.pay()
							} else if (this.pays == 'epay') {
								// 易支付
								let params = {
									target_id: this.massage_pay.trade_id,
									target_type: this.massage_pay.target_type,
									pay_type: this.pays,
									total_amount: this.massage_pay.total_amount,
									type: this.params.epay_type,
									method: this.params.method,
									trade_pwd: password,
									// 根据不同平台设置不同的client参数
									// #ifdef APP-PLUS
									client: 'APP',
									// #endif
									// #ifdef MP-WEIXIN || MP-ALIPAY
									client: 'JSAPI',
									// #endif
									// #ifdef H5
									client: 'WAP',
									// #endif
								}
								this.$com.easyPay(params, this.pays);
							} else {
								let params = {
									target_id: this.massage_pay.trade_id,
									target_type: this.massage_pay.target_type,
									pay_type: this.pays,
									total_amount: this.massage_pay.total_amount,
									// #ifdef MP-WEIXIN
									client: 'JSAPI',
									// #endif
									// #ifdef MP-WEIXIN
									client: 'APP',
									// #endif
								}
								// #ifdef APP-PLUS
								this.$com.wxPay(params, this.pays).then(ok => {
									this.$refs.uToast.show({
										title: ok.data.msg,
										type: 'success',
										callback: cal => {
											// this.$u.route({
											// 	type: 'reLaunch',
											// 	url: '/pages/my/my'
											// })
											this.paySucess()
										}
									})
								}).catch((err) => {
									this.isPayType = true
								})
								// #endif
								// #ifdef MP-WEIXIN
								this.$com.weChatPay(params, this.pays).then(ok => {
									this.$refs.uToast.show({
										title: ok.data.msg,
										type: 'success',
										callback: cal => {
											// this.$u.route({
											// 	type: 'reLaunch',
											// 	url: '/pages/my/my'
											// })
											this.paySucess()
										}
									})
								}).catch((err) => {
									this.isPayType = true
								})
								// #endif
							}

						} else {
							uni.showToast({
								icon: 'error',
								title: res.data.msg
							})
						}
					})
				}
			}
		},
		paySucess() {
			let goodsName = this.userinfo.items[0].goods[0].goods_name
			let payType = ''

			if (this.pays == 'alipay') {
				payType = '支付宝'
			}
			if (this.pays == 'wechat') {
				payType = '微信'
			}
			if (this.pays == 'deposit') {
				payType = '钱包余额'
			}
			if (this.pays == 'epay') {
				payType = '易支付'
			}
			const payMoney = this.userinfo.pay_amount
			const base_url = 'http://xcx.itcwc.com/member/#/'

			// #ifdef APP-PLUS
	
				this.$u.route({
					type: 'reLaunch',
					url: `/subcontract/payStatus/payStatus?goodsName=${goodsName}&payType=${payType}&payMoney=${payMoney}`
				})
			// uni.navigateTo({
			// 	url: '/pages/webview/webview?url=' + encodeURIComponent(`${base_url}/subcontract/payStatus/payStatus?goodsName=${goodsName}&payType=${payType}&payMoney=${payMoney}`)
			// });
			// #endif
			// #ifdef H5
			this.$u.route({
				type: 'reLaunch',
				url: `/subcontract/payStatus/payStatus?goodsName=${goodsName}&payType=${payType}&payMoney=${payMoney}`
			})
			// #endif
		},

		pay(trade_pwd) {
			console.log(this.massage_pay)
			uni.showLoading({
				title: '支付中',
				mask: true
			});
			this.$api.go_pay({
				target_id: this.massage_pay.trade_id,
				target_type: this.massage_pay.target_type,
				pay_type: this.pays,
				client: "APP",
				trade_pwd: trade_pwd
			}, res => {
				uni.hideLoading();
				if (res.data.code == 1) {
					uni.showToast({
						icon: 'success',
						title: '支付成功'
					})
					setTimeout(() => {
						// uni.switchTab({
						// 	url: '/pages/my/my'
						// })
						this.paySucess()
					}, 500)

				} else {
					this.isPayType = true
					uni.showToast({
						icon: 'none',
						title: res.data.msg
					})
				}
			})
		},
		openEpayDialog() {
			this.pays = 'epay' // 设置支付类型为epay
			this.showEpayDialog = true
		},

		selectEpayMethod(method) {
			this.params.epay_type = method
		},

		confirmEpayMethod() {
			this.showEpayDialog = false
		},
	}
}
</script>

<style scoped lang="scss">
page {
	background: #F5F5F5FF !important;
}

.deduct {
	::v-deep(.u-checkbox) {
		display: block
	}
}

/* 易支付选择弹窗样式 */
.epay-dialog {
	background-color: #fff;
	padding: 30rpx;
}

.epay-dialog-title {
	font-size: 32rpx;
	font-weight: bold;
	text-align: center;
	margin-bottom: 30rpx;
}

.epay-dialog-content {
	padding: 20rpx 0;
}

.epay-payment-option {
	display: flex;
	align-items: center;
	padding: 20rpx 0;
	border-bottom: 1rpx solid #f5f5f5;
}

.radio-button {
	width: 36rpx;
	height: 36rpx;
	border-radius: 50%;
	border: 2rpx solid #ddd;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-right: 20rpx;
}

.radio-inner {
	width: 20rpx;
	height: 20rpx;
	border-radius: 50%;
	background-color: transparent;
}

.radio-selected {
	background-color: #3298FD;
}

.payment-icon {
	margin-right: 20rpx;
}

.payment-name {
	font-size: 28rpx;
}

.epay-dialog-footer {
	display: flex;
	justify-content: space-between;
	margin-top: 40rpx;
}

.epay-dialog-btn {
	width: 45%;
	height: 80rpx;
	border-radius: 40rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 28rpx;
}

.cancel-btn {
	background-color: #f5f5f5;
	color: #666;
}

.confirm-btn {
	background-color: #3298FD;
	color: #fff;
}
</style>